{% from 'bootstrap/form.html' import render_form %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="{{ url_for('static',filename='js/jquery-3.6.0.min.js') }}"> </script>
</head>
<body>
    <div>
        {{ render_form(form,action=request.full_path) }}
        {% if operation=='登陆' %}
            <button type="button" onclick="send_cache();">获取验证码</button>
        <a class="btn" type="button" href="{{ url_for('auth.login') }}">
            {{ operation }}</a>
        {% else %}
        <a class="btn" type="button" href="{{ url_for('auth.register') }}">
            {{ operation }}</a>
        {% endif %}
    </div>
    {% for msg in get_flashed_messages() %}
        <p class="err">{{ msg }}</p>
    {% endfor %}
</body>
<script type="text/javascript">
    function send_cache(){
        let cache=$('#cache').val();
        let email=$('#email').val();
        $.ajax({
            data:{'cache':cache,'email':email},
            url:'{{ url_for('auth.send_cache') }}',
            type:'post',
            success:function (data) {
                if (data['data']==true){
                    alert('验证已发送');
                }
                else{
                    alert('该邮箱不存在');
                }
            }
        });
    }
</script>
</html>